﻿@model IList<Shop.Page.Models.HomeBottom>
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>底部链接管理里</title>
    <link href="~/Content/BootStrap/css/bootstrap.min.css" rel="stylesheet" />
    <link href="~/Content/BootStrap/css/bootstrap-theme.min.css" rel="stylesheet" />
    <link href="~/Content/BootStrap/css/docs.min.css" rel="stylesheet" />
    <link href="~/bootstrapvalidator-master/dist/css/bootstrapValidator.min.css" rel="stylesheet" />

    <script src="~/Scripts/jquery-1.10.2.min.js"></script>
    <script src="~/Content/BootStrap/js/bootstrap.min.js"></script>
    <script src="~/Content/BootStrap/js/docs.min.js"></script>
    <script src="~/bootstrapvalidator-master/dist/js/bootstrapValidator.min.js"></script>
    <script src="~/bootstrapvalidator-master/dist/js/language/zh_CN.js"></script>
</head>
<body>

    <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#AddHomeBottom">
        添加标题
    </button>
    @*添加弹出层*@
    <div class="modal fade bs-example-modal-lg" id="AddHomeBottom" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">添加标题</h4>
                </div>
                <form id="AddHomeBottomInfo" method="post" class="form-horizontal" action="AddHomeBottomInfo">
                    <div class="modal-body">
                        <div class="form-group">
                            <label class="col-lg-3 control-label">标题名</label>
                            <div class="col-lg-5">
                                <input type="text" class="form-control" name="HBName" id="HBName" placeholder="标题名" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-3 control-label">链接</label>
                            <div class="col-lg-5">
                                <input type="text" class="form-control" name="HBHref" id="HBHref" placeholder="链接(可以不填)" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-3 control-label" for="Superior">所属</label>
                            <div class="col-lg-5">
                                <select class="form-control" name="Superior" id="Superior">
                                    @foreach (var item in Model)
                                    {
                                        <option value="@item.HBID">@item.HBName</option>
                                    }
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <input type="button" class="btn btn-default" data-dismiss="modal" value="关闭" />
                        <input type="submit" class="btn btn-primary" value="确定" />
                    </div>
                </form>
            </div>
        </div>
    </div>
    <table class="table table-bordered table-striped table-hover">
        <tr>
            <td>#</td>
            <td>标题名</td>
            <td>链接</td>
            <td>操作</td>
        </tr>
        @for (int i = 0; i < Model.Count; i++)
        {
            <tr>
                <td>@(i+1)</td>
                <td>@Model[i].HBName</td>
                <td>@Model[i].HBHref</td>
                <td>
                    <input type="button" class="btn btn-default" value="修改" onclick="updates(@(Model[i].HBID), '@Model[i].HBName', '@Model[i].HBHref')" />
                </td>
            </tr>
            @Html.Action("_HomeBottom", "Page",new { Superior = Model[i].HBID})
            
        }
    </table>


    <div class="modal fade bs-example-modal-lg" id="UpdateHomeBottom" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">修改标题</h4>
                </div>
                <form id="UpdateHomeBottomInfo" method="post" class="form-horizontal" action="UpdateHomeBottomInfo">
                    <input type="text" hidden="hidden" name="HBID" id="HBID" />
                    <div class="modal-body">
                        <div class="form-group">
                            <label class="col-lg-3 control-label">标题名</label>
                            <div class="col-lg-5">
                                <input type="text" class="form-control" name="UHBName" id="UHBName" placeholder="标题名" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-3 control-label">链接</label>
                            <div class="col-lg-5">
                                <input type="text" class="form-control" name="UHBHref" id="UHBHref" placeholder="链接(可以不填)" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-3 control-label" for="USuperior">所属</label>
                            <div class="col-lg-5">
                                <select class="form-control" name="USuperior" id="USuperior">
                                    @foreach (var item in Model)
                                    {
                                        <option value="@item.HBID">@item.HBName</option>
                                    }
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <input type="button" class="btn btn-default" data-dismiss="modal" value="关闭" />
                        <input type="submit" class="btn btn-primary" value="确定" />
                    </div>
                </form>
            </div>
        </div>
    </div>


    <div class="modal fade bs-example-modal-lg" id="UpdateHomeBottoms" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">修改标题</h4>
                </div>
                <form id="UpdateHomeBottomInfos" method="post" class="form-horizontal" action="UpdateHomeBottomInfo">
                    <input type="text" hidden="hidden" name="HBID" id="HBIDs" />
                    <div class="modal-body">
                        <div class="form-group">
                            <label class="col-lg-3 control-label">标题名</label>
                            <div class="col-lg-5">
                                <input type="text" class="form-control" name="UHBName" id="UHBNames" placeholder="标题名" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-3 control-label">链接</label>
                            <div class="col-lg-5">
                                <input type="text" class="form-control" name="UHBHref" id="UHBHrefs" placeholder="链接(可以不填)" />
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <input type="button" class="btn btn-default" data-dismiss="modal" value="关闭" />
                        <input type="submit" class="btn btn-primary" value="确定" />
                    </div>
                </form>
            </div>
        </div>
    </div>

    <script type="text/javascript">
        //添加
        $(document).ready(function () {
            $('#AddHomeBottomInfo')
                .bootstrapValidator({
                    message: 'This value is not valid',
                    feedbackIcons: {
                        valid: 'glyphicon glyphicon-ok',
                        invalid: 'glyphicon glyphicon-remove',
                        validating: 'glyphicon glyphicon-refresh'
                    },
                    fields: {
                        'HBName': {
                            validators: {
                                notEmpty: {
                                    message: '标题不能为空'
                                },
                                stringLength: {
                                    max: 10,
                                    message: '类别描述最多10个字符'
                                }
                            }
                        }
                    }
                });
        });
        //修改
        $(document).ready(function () {
            $('#UpdateHomeBottomInfo')
                .bootstrapValidator({
                    message: 'This value is not valid',
                    feedbackIcons: {
                        valid: 'glyphicon glyphicon-ok',
                        invalid: 'glyphicon glyphicon-remove',
                        validating: 'glyphicon glyphicon-refresh'
                    },
                    fields: {
                        'HBName': {
                            validators: {
                                notEmpty: {
                                    message: '标题不能为空'
                                },
                                stringLength: {
                                    max: 10,
                                    message: '类别描述最多10个字符'
                                }
                            }
                        }
                    }
                });
        });
        function update(HBID, HBName, HBHref, Superior) {
            $("#HBID").val(HBID);
            $("#UHBName").val(HBName);
            $("#UHBHref").val(HBHref);
            $("#USuperior").val(Superior);
            $("#UpdateHomeBottom").modal();
        }
        function updates(HBID, HBName, HBHref) {
            $("#HBIDs").val(HBID);
            $("#UHBNames").val(HBName);
            $("#UHBHrefs").val(HBHref);
            $("#UpdateHomeBottoms").modal();
        }
        function del(HBID)
        {
            var gnl = confirm("确定要删除?");
            if (gnl == true) {
                $.ajax({
                    url: '@Url.Action("DelHomeBottomInfo")',
                    type: 'post',
                    dataType: 'text',
                    async: false,
                    data: { HBID: HBID },
                    success: function (data) {
                        if (data == "NO") {
                            alert("删除失败");
                        }
                        else {
                            alert("删除成功");
                            window.location.reload();
                        }
                    }
                });
            }
        }
        //置顶类别
        function stick(HBID) {
            var gnl = confirm("确定要置顶吗?");
            if (gnl == true) {
                $.ajax({
                    url: '@Url.Action("OrderHomeBottomInfo")',
                    type: 'post',
                    dataType: 'text',
                    async: false,
                    data: { HBID: HBID },
                    success: function (data) {
                        if (data == "NO") {
                            alert("置顶失败");
                        }
                        else {
                            alert("置顶成功");
                            window.location.reload();
                        }
                    }
                });
            }
        }
    </script>
</body>
</html>
